package com.example.lotterysystem.common.exception;

import com.example.lotterysystem.common.errorcode.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/*
控制层异常类
 */
//Data重写没有equal和hashcode的方法,需要用EqualsAndHashCode进行重写
@Data
@EqualsAndHashCode(callSuper = true)
public class ControllerException extends RuntimeException{
    /**
     * 业务错误码
     * @see com.example.lotterysystem.common.errorcode.ControllerErrorCodeConstants
     */
    private Integer code;
    /**
     * 错误信息
     */
    private String message;

    public ControllerException(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    //空构造方法,避免反序列化问题
    public ControllerException() {
    }

    public ControllerException(ErrorCode errorCode){
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }
}

